package com.atguigu.marketing.service.impl;

import com.alibaba.fastjson.JSON;
import com.atguigu.marketing.bean.DimUserInfo;
import com.atguigu.marketing.mapper.DimUserInfoMapper;
import com.atguigu.marketing.service.DimUserInfoService;
import com.atguigu.userprofile.utils.RedisUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;

@Service
@DS("dim-phoenix")
public class DimUserInfoServiceImpl extends ServiceImpl<DimUserInfoMapper, DimUserInfo> implements DimUserInfoService  {


    public DimUserInfo getDimUserInfoWithCache(String uid) {
        Jedis jedis = RedisUtil.getJedis();
        String dimUserkey="dim:user_info:"+uid;
        String userJson  = jedis.get(dimUserkey);
        DimUserInfo dimUserInfo;
        if(userJson!=null){
            dimUserInfo  = JSON.parseObject(userJson, DimUserInfo.class);

        }else{
            dimUserInfo = getById(uid);
            userJson=JSON.toJSONString(dimUserInfo);
            jedis.set(dimUserkey,userJson);
        }
        return dimUserInfo;




    }
}
